package com.mtw.bbs.article.feign;


import com.mtw.bbs.article.pojo.form.LikeCountForm;
import com.mtw.bbs.article.pojo.vo.LikeCountVo;
import com.mtw.bbs.common.core.vo.Result;
import com.mtw.bbs.common.web.interceptor.BaseFeignInterceptor;
import io.swagger.annotations.ApiOperation;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.mtw.bbs.common.core.constant.ApiPrefix.API_PREFIX_LIKE;


/**
 * like Feign接口类
 */
@FeignClient(
        value = "bbs-article",
        contextId = "likeClientI",
        configuration = BaseFeignInterceptor.class,
        fallback = LikeClient.LikeClientFallback.class
)
public interface LikeClient {


    @ApiOperation(value = "根据用户id，获取用户获赞总数", notes = "")
    @GetMapping(value = API_PREFIX_LIKE+"/getUserLikeCount",headers = "Content-Type=application/json")
    Result<Integer> getUserLikeCount(@RequestParam("uid") String uid);



    @ApiOperation(value = "根据用户id，业务id和实体id判断用户是否已点赞", notes = "")
    @PostMapping(value = API_PREFIX_LIKE+"/getLiked",headers = "Content-Type=application/json")
    Result<LikeCountVo> getIsLikedByUserAndBusAndMessageId(@RequestBody LikeCountForm form);



    @ApiOperation(value = "根据用户id，业务id和实体id集合判断用户是否已点赞", notes = "")
    @PostMapping(value = API_PREFIX_LIKE+"/getLikedList",headers = "Content-Type=application/json")
    Result<List<LikeCountVo>> getIsLikedByUserAndBusAndMessageIds(@RequestBody LikeCountForm form);


    @ApiOperation(value = "根据用户id，业务id和实体id判断用户是否已点赞，并带出已点赞数量", notes = "")
    @PostMapping(value = API_PREFIX_LIKE+"/getLikedWithCount",headers = "Content-Type=application/json")
    Result<LikeCountVo> getIsLikedByUserAndBusAndMessageIdWithCount(@RequestBody LikeCountForm form);



    @ApiOperation(value = "根据用户id，业务id和实体id集合判断用户是否已点赞，并带出已点赞数量", notes = "")
    @PostMapping(value = API_PREFIX_LIKE+"/getLikedListWithCount",headers = "Content-Type=application/json")
    Result<List<LikeCountVo>> getIsLikedByUserAndBusAndMessageIdsWithCount(@RequestBody LikeCountForm form);



    @ApiOperation(value = "根据用业务id和实体id获取点赞数量", notes = "")
    @PostMapping(value = API_PREFIX_LIKE+"/getCount",headers = "Content-Type=application/json")
    Result<LikeCountVo> getCountByBusAndMessageId(@RequestBody LikeCountForm form);



    @ApiOperation(value = "根据用业务id和实体id集合获取点赞数量", notes = "")
    @PostMapping(value = API_PREFIX_LIKE+"/getCountList",headers = "Content-Type=application/json")
    Result<List<LikeCountVo>> getCountByBusAndMessageIds(@RequestBody LikeCountForm form);


    @ApiOperation(value = "根据用业务id和用户id获取已点对象id", notes = "")
    @GetMapping(value = API_PREFIX_LIKE+"/getUserLikeList/{userId}")
    Result<List<String>> getUserLikeList(@PathVariable("userId") String userId,@RequestParam(name = "page") int page,
                                         @RequestParam(name = "size") int size,@RequestParam(name = "objectType") String objectType);



    /**
     * Feign失败配置
     */
    @Component("likeClient")
    class LikeClientFallback implements LikeClient {


        @Override
        public Result<Integer> getUserLikeCount(String uid) {
            return Result.fail("获取失败");
        }

        @Override
        public Result<LikeCountVo> getIsLikedByUserAndBusAndMessageId(LikeCountForm form) {
            return Result.fail("获取失败");
        }

        @Override
        public Result<List<LikeCountVo>> getIsLikedByUserAndBusAndMessageIds(LikeCountForm form) {
            return Result.fail("获取失败");
        }

        @Override
        public Result<LikeCountVo> getIsLikedByUserAndBusAndMessageIdWithCount(LikeCountForm form) {
            return Result.fail("获取失败");
        }

        @Override
        public Result<List<LikeCountVo>> getIsLikedByUserAndBusAndMessageIdsWithCount(LikeCountForm form) {
            return Result.fail("获取失败");
        }

        @Override
        public Result<LikeCountVo> getCountByBusAndMessageId(LikeCountForm form) {
            return Result.fail("获取失败");
        }

        @Override
        public Result<List<LikeCountVo>> getCountByBusAndMessageIds(LikeCountForm form) {
            return Result.fail("获取失败");
        }

        @Override
        public Result<List<String>> getUserLikeList(String userId, int page, int size, String objectType) {
            return Result.fail("获取失败");
        }
    }

}
